using System;
using System.Drawing;
using DirectX.Capture;
using System.Windows.Forms;
using System.Collections.Generic;

namespace Webcam
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// Configures the input options
        /// </summary>
        private void Configure()
        {
            try
            {
                if (comboBox1.Items.Count < 1)
                    throw new Exception();
                comboBox1.Enabled = false;
                //comboBox2.Enabled = false;
                this.button1.Enabled = true;
                this.VideoInput = this.InputOptions.VideoInputDevices[comboBox1.SelectedIndex];
                /*if (comboBox2.Items.Count > 0)
                    this.AudioInput = this.InputOptions.AudioInputDevices[comboBox2.SelectedIndex];*/
                this.CaptureInfo = new Capture(this.VideoInput, null);
                //this.AudioInput);
                this.CaptureInfo.PreviewWindow = pictureBox1;
                this.CaptureInfo.RenderPreview();
                this.CaptureInfo.FrameCaptureComplete += new Capture.FrameCapHandler(CaptureInfo_FrameCaptureComplete);
                this.button2.Enabled = true;
                this.button1.Enabled = false;
            }
            catch(Exception e)
            {
                this.ErrorMessage(e);
            }
        }

        /// <summary>
        /// Is Handled when a capture has been successfully taken
        /// </summary>
        /// <param name="Frame">The picturebox that has been generated</param>
        void CaptureInfo_FrameCaptureComplete(PictureBox Frame)
        {
            pictureBox2.Image = Frame.Image;
        }
    }
}